package j.util.jdbc.simple.metadata;

import j.util.jdbc.simple.annotation.DataType;

/**
 * 数据库一个字段的元数据信息
 * 
 * @author 刘军海
 * @version Sep 7, 2011 10:57:39 AM
 *
 */
public class Column {

	/**
	 * 字段名,是数据库表中的字段名
	 */
	private String name;
    /**
     * 实体属性名称
     */
    private String entityAttributeName;
	/**
	 * 字段类型
	 */
	private DataType dataType = DataType.AUTO;
	/**
	 * 该字段在数据库中的设置是否为空，默认允许为空
	 */
	private boolean nullable = true;
	/**
	 * 在数据库中的设置是否有默认值
	 */
	private boolean hasDefaultValue = false;

    private boolean isInsertable = true;
    private boolean isUpdatable = true;

    private boolean isSuperClassField = false;
	
	public Column(String name,String entityAttributeName){
		this.name = name;
        this.entityAttributeName = entityAttributeName;
	}
	
	public String getName() {
		return name;
	}
    public String getEntityAttributeName(){
        return entityAttributeName;
    }
	public DataType getDataType() {
		return dataType;
	}
	public void setDataType(DataType dataType) {
		this.dataType = dataType;
	}
	public boolean isNullable() {
		return nullable;
	}
	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}
	/**
	 * 在数据库中的设置是否有默认值
	 */
	public boolean isHasDefaultValue() {
		return hasDefaultValue;
	}
	public void setHasDefaultValue(boolean hasDefaultValue) {
		this.hasDefaultValue = hasDefaultValue;
	}

    public boolean isInsertable() {
        return isInsertable;
    }
    public void setInsertable(boolean insertable) {
        isInsertable = insertable;
    }

    public boolean isUpdatable() {
        return isUpdatable;
    }
    public void setUpdatable(boolean updatable) {
        isUpdatable = updatable;
    }

    public boolean isSuperClassField() {
        return isSuperClassField;
    }
    public void setSuperClassField(boolean isSuperClassField) {
        this.isSuperClassField = isSuperClassField;
    }

    @Override
	public int hashCode() {
		return this.name.hashCode();
	}
	@Override
	public boolean equals(Object obj) {
		Column c = (Column)obj;
		return this.name.equals(c.getName());
	}
	@Override
	public String toString() {
		return this.name;
	}
}
